package com.bwf.jdbc;

import java.sql.*;
import java.util.ArrayList;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/6/1 15:28
 * @Copyright 博为峰
 */
public class ClaDao {
//    public Connection getConn() throws SQLException {
//        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?serverTimezone=UTC", "root", "123456");
//        return connection;
//    }

    public ArrayList<Cla> query() throws Exception {
        ArrayList<Cla> list = new ArrayList<>();
        Connection connection = DBUtil.getConn();
        PreparedStatement preparedStatement = connection.prepareStatement("select * from t_class");
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            int num = resultSet.getInt("num");
            Cla cla = new Cla(id, name, num);
            list.add(cla);
        }
        return list;
    }
}
